#include "doge_list.h"
#include "stdio.h"
#include "string.h"

struct person {
    d_list_t list;
    int age;
};

DOGE_LIST_DEFINE(PersonList);

void Person_Add(struct person *p, int age)
{
    p->age = age;
    doge_list_add(&p->list, &PersonList);
}

void Person_Remove(struct person *p)
{
    doge_list_del(&p->list);
}

void Person_Foreach(void)
{
    d_list_t *cur;
    d_list_t *next;
    struct person *p;

    DOGE_LIST_FOR_EACH_SAFE(cur, next, &PersonList)
    {
        p = DOGE_LIST_ENTRY(cur, struct person, list);
        if (p != NULL)
        {
            printf("age = %d\r\n", p->age);
        }
    }
}





int main(int argc, char **argv)
{
    doge_list_init(&PersonList);

    struct person zhanshan;
    struct person lisi;
    struct person wangwu;

    Person_Add(&zhanshan, 10);
    Person_Add(&lisi, 40);
    Person_Add(&wangwu, 30);

    Person_Foreach();

    Person_Remove(&wangwu);

    printf("\r\n");

    Person_Foreach();


    return 0;
}